<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Admin extends Controller
{
	function Admin()
	{
		parent::Controller();
		
	}

	function index()
	{
			$this->load->view('login');
	}
	function login()
	{
	    session_start(); 
		$username = $this->input->xss_clean($this->input->post('username'));    
	    $password = md5($this->input->post('password'));
		$result=$this->user_model->check_login($username,$password);
		if($result->num_rows()>0)
		{
	       foreach ($result->result() as $row)
			{
					$_SESSION['username']=$username;
					$_SESSION['password']=$password;
					$_SESSION['user_ID']=$row->admin_id;
					$_SESSION['logged_in_status']=1;
					$_SESSION['ua_user_status']=true; // use in frontend
					//echo $_SESSION['logged_in_status'];
			}
                //$this->session->set_userdata($data);
                redirect('/adminpage/cpanel/');
		}
		else
		{
	        $this->session->set_flashdata('message', '<div id="message">Oopsie, Username or password is incorrect</div>');
	        redirect('/admin/');

		}
    }
	function checkpass($pass='')      	    // ajax
	{	
		if ($pass!='')
		{
			$result=$_SESSION['password']<>$pass?0:1;
			if ($result)
			{
				echo "<img src='".base_url()."/assets/img/checked.gif' align='absmiddle'/> ".$this->lang->line('f_right_password').'<input type="hidden" id="correctpass" value=1 />';
			}
			else
			{
				echo "<img src='".base_url()."/assets/img/unchecked.gif' align='absmiddle'/> ".$this->lang->line('f_wrong_password').'<input type="hidden" id="correctpass" value=0 />';
			}
		}
	}

	function logout()
	{
	     //$this->session->sess_destroy();
		//$this->session->unset_userdata('logged_in_status');
		 session_start(); 
		unset($_SESSION['logged_in_status']);
	    redirect('/admin/');
	}
}
?>